import http from "@/utils/request/httpRequest.ts";
import type {MenuAddType, MenuListResType} from "@/types/MenuType.ts";
import type {ListType} from "@/types/commonType.ts";
import type {LoginSubmitResponsePermissionTreeDTOListType} from "@/types/loginType.ts";
import Local from "@/utils/local";

// 一级菜单列表
export const menuList = (data?: {
    name: string;
}) => http.get<MenuListResType[]>('sys/permission/getPermissionTree', {
    params: data
})

// 二级菜单列表
export const subMenuList = (data: {
    parentId: string
}) => http.get<ListType<MenuListResType[]>>('sys/permission/getSystemSubmenu', {
    params: data
})

//添加菜单
// sys/permission/add
export const menuAdd = (data: MenuAddType) => http.post('sys/permission/add', data)

// 获取当前权限所有菜单
export const getUserMenuList = () => {
    const roleId = Local.localRead('roleId')
    return http.get<LoginSubmitResponsePermissionTreeDTOListType[]>('sys/permission/getUserMenuList', {
        params: {
            roleId
        }
    })
}

// 删除
export const menuDelete = (data: string[]) => http.post<string>('sys/permission/deleteByIds', data)

// 修改菜单
export const menuUpdate = (data: MenuAddType) => http.post('sys/permission/update', data)